import Dexie, { type EntityTable } from 'dexie'
import type { ProviderSelectProps, ConversationProps, MessageListProps } from './type'
import { providerList } from './testData'
export const db = new Dexie('vchatDb') as Dexie & {
  providers: EntityTable<ProviderSelectProps, 'id'>
  conversations: EntityTable<ConversationProps, 'id'>
  messages: EntityTable<MessageListProps, 'id'>
}
db.version(1).stores({
  providers: '++id, name',
  conversations: '++id, providerid',
  messages: '++id, conversationid'
})

export const initProviders = async () => {
  const count = await db.providers.count()
  if (count === 0) {
    await db.providers.bulkAdd(providerList)
  }
}
